// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var validate = require("validate");
	var css_param = require("./wareHousePickupList.css");
	var tools = require("tools");
	var databind = require("databind");
	var constant = require("constant");
	var leftMenu = require("../leftMenu/leftMenu");
	var router = require("../hash/pageRouter");
	var html_financeContract = require("./html_financeContract.html");
	var html_contractConfirm = require("./html_contractConfirm.html");
	var html_documentSign = require("./html_documentSign.html");
	var html_signFileSealList = require("./html_signFileSealList.html");
	var html_signCallback = require("./html_signCallback.html");
	var html_signReplace = require("./html_signReplace.html");
	var html_signCallbackAll = require("./html_signCallbackAll.html");
	var warehousePickupdocumentSign = require("./warehousePickupdocumentSign.html");
	var ei;
	var tf = false;;
	var ii;
	var ii2;
	var ii3;
	var ii4;
	var record;
	var pickupState;
	var pageIndex = 1,
        pageSize = 10,
        totalPageCount = 1,
        totalRecordCount = 0; //分页初始化
	var init = function(page) {
		pickupState = page.params.pickupState || base.getUrlParam("pickupState");
//		leftMenu.init(11);
		router.init();
		initEvent();
	};
	var oData = {};
	
	var initEvent = function() {
		oData = {
			pageIndex : 1,
	        pageSize : 10,
	        totalPageCount : 1,
	        totalRecordCount : 0,//分页初始化
	        pickupState: eval ("(" + pickupState + ")")
		}
		
		if (pickupState != null) {
			$("#wareHousePickupList select[name=pickupState]").html("<option value='"+pickupState+"'>待办</option><option value=''>全部</option>");
		} else {
			
		}
		tools.loadSelectList($("#wareHousePickupList select[name=enterpriseId]"), "inquireEnterpriseList.json", "id", "name", null);
		tools.autocomplete($("#wareHousePickupList select[name=enterpriseId]"));
		
		loadPickupList(oData);
		
		$("#accountRecordApplySearchButton").unbind("click").click(function(){
			var ps;
			if ($("#wareHousePickupList select[name=pickupState]").val() != "") {
				ps = eval ("(" + $("#wareHousePickupList select[name=pickupState]").val() + ")")
			} else {
				if (eval ("(" + pickupState + ")") == 11) {
					ps = eval ("([11,12])")
				} else {
					ps = "";
				}
			}
			var oData = {
				pageIndex : 1,
		        pageSize : 10,
		        totalPageCount : 1,
		        totalRecordCount : 0,//分页初始化
		        pickupState: ps,
		        pickupNumber: $("#wareHousePickupList input[name=pickupNumber]").val(),
		        creator: $("#wareHousePickupList input[name=creator]").val(),
		        screatDt:$("#wareHousePickupList input[name=dateBegin]").val(),
		        ecreatDt:$("#wareHousePickupList input[name=dateEnd]").val(),
		        enterpriseId:$("#wareHousePickupList select[name=enterpriseId]").val(),
		        buyer:$("#wareHousePickupList input[name=buyer]").val(),
		        spickupDt:$("#wareHousePickupList input[name=dateBegin2]").val(),
		        epickupDt:$("#wareHousePickupList input[name=dateEnd2]").val(),
		        productType:$("#wareHousePickupList select[name=productType]").val(),
		        financeNumber:$("#wareHousePickupList input[name=financeNumber]").val(),
		        warehouseName:$("#wareHousePickupList input[name=warehouseName]").val(),
			}
			loadPickupList(oData);
		});
		
		//查看融资详情
		$("#wareHousePickupList").on("click", ".showFinanceDetail", function() {
			var $thisParent = $(this).parents("tr");
			var financeId = $thisParent.attr("financeId");
			//其他样式
			var tr1 = $thisParent.prevAll("tr[pickupNumber1="+ $(this).attr("pickupNumber") +"]");
			var td1 = tr1.children().first();
			var tr2 = tr1.next();
			var td9 = tr2.children().eq(9);
			var td8 = tr2.children().eq(8);
			var newRowspan;
			var newRowspan1;
			if($thisParent.next().is(":hidden")) {
				$thisParent.next().show();
				$(this).html("&nbsp;&nbsp;[-]");
				
				newRowspan = parseFloat(td1.attr("rowspan")) + 1;
				td1.attr("rowspan", newRowspan);
				
				newRowspan1 = parseFloat(td9.attr("rowspan")) + 1;
				td8.nextAll().attr("rowspan", newRowspan1);
			}else {
				$thisParent.next().hide();
				$(this).html("&nbsp;&nbsp;[+]");
				
					//其他样式
				newRowspan = parseFloat(td1.attr("rowspan")) - 1;
				td1.attr("rowspan", newRowspan);
				
				newRowspan1 = parseFloat(td9.attr("rowspan")) - 1;
				td8.nextAll().attr("rowspan", newRowspan1);
			}
			
			if($thisParent.next().attr("isNull") != "1") {
				inquireFinanceApplicationDetail($thisParent.next(),financeId);
			}
		});
		
	};
	
	var loadPickupList = function(oData) {
		 $("#wareHousePickupList .outerTable").html("");
		tools.loadList("inquireFinancePickupApplicationWarehousePageList.json", $("#wareHousePickupList .outerTable"), $("#wareHousePickupList script"),
				oData, function(data){
					
			if (pickupState != 6) {
				$(".platformSign").remove();
			} else {
				$(".release").remove();
				$(".ouInfo").remove();
			}
			
			//委托方
			$("#wareHousePickupList .enter_name").unbind("click").click(function() {
				router.route("client/clientManage_details.html?enterpriseId="+$(this).parents("tr").attr("enterpriseId"));
			});
			//点击融资编号
			$("#wareHousePickupList .order_num").unbind("click").click(function() {
				router.route("financing/financingDetailInfo.html?financeId=" + $(this).parents("tr").attr("financeId"));
			});
			
			//初审
			$("#wareHousePickupList .audit").unbind("click").click(function(){
				router.route("warehousePickup/approvelConsignment.html?pickupId="+ $(this).parents("tr").attr("pickupId"));
			});
			
			//出库详情
			$("#wareHousePickupList .ouInfo").unbind("click").click(function(){
				router.route("warehousePickup/wareHouseDetail.html?pickupNumber="+ $(this).attr("pickupNumber") + "&warehouseId="+ $(this).attr("warehouseId"));
			});
			
			//政审
			$("#wareHousePickupList .careful").unbind("click").click(function(){
				router.route("warehousePickup/approvelCarefulManage.html?pickupId="+ $(this).parents("tr").attr("pickupId"));
			});
			
			//详情
			$("#wareHousePickupList .detail").unbind("click").click(function(){
				var productType = $(this).parents("tr").attr("productType");
				if(productType == 6) { //代销提货
					router.route("warehousePickup/createPickupDetail.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
				}else if(productType == 5) { //代采提货
					router.route("warehousePickup/createPickupDetail1.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
				}
			});
			
			//提单号
			$("#wareHousePickupList .pickups_num").unbind("click").click(function() {
				var productType = $(this).parents("tr").attr("productType");
				if(productType == 6) { //代销提货
					router.route("warehousePickup/createPickupDetail.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
				}else if(productType == 5) { //代采提货
					router.route("warehousePickup/createPickupDetail1.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
				}
			});
			
			//修改
			$("#wareHousePickupList .update").unbind("click").click(function(){
				var productType = $(this).parents("tr").attr("productType");
				if(productType == 6) { //代销提货
					router.route("warehousePickup/updatePickup.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
				}else if(productType == 5) { //代采提货
					router.route("warehousePickup/updatePickup1.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
				}
			});
			
			//客户签署
			$("#wareHousePickupList .documentSign_s2").unbind("click").click(function(){
				var pickupId = $(this).parents("tr").attr("pickupId");
				
				ii = layer.open({
				  title: '合同信息',
				  type: 1,
				  skin: 'layui-layer-rim', //加上边框
				  area: ['1000px', '600px'], //宽高
				  content: warehousePickupdocumentSign,
				  btn: ['确定']
				});
				
				inquireFinancePickupApplicationWarehouse3(pickupId);
//				router.route("warehousePickup/warehousePickupdocumentSign.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
			});
			
			//平台签署
			$("#wareHousePickupList .platformSign").unbind("click").click(function(){
				var $this = $(this);
				
				ii = layer.open({
				  title: '合同信息',
				  type: 1,
				  skin: 'layui-layer-rim', //加上边框
				  area: ['1000px', '600px'], //宽高
				  content: html_documentSign,
				  btn: ['确定']
				});
				
				inquireFinancePickupApplicationWarehouse1($this.parents("tr").attr("pickupId"));
			});
			
			// 点击合同确认
			$("#wareHousePickupList .contractConfirm").unbind("click").click(function() {
				var $this = $(this);
				ii = layer.open({
				  type: 1,
				  title: "合同确认",
				  skin: 'layui-layer-rim', //加上边框
				  area: ['1000px', '600px'], //宽高
				  content: html_contractConfirm,
				  btn: ['确定'],
				  yes: function(){
				  	if ($(".confirm").length > 0) {
				  		base.alert(2, "还有合同尚未确认！");
				  		return false;
				  	} else {
				  		layer.close(ii);
//				  		inquireFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"));
//				  		router.route("warehousePickup/wareHousePickupList.html");
				  		loadPickupList(oData);
				  	}
				  },
				  cancel: function(){
				  	if ($(".confirm").length > 0) {
				  		base.alert(2, "还有合同尚未确认！");
				  		return false;
				  	} else {
				  		layer.close(ii);
				  		loadPickupList(oData);
				  	}
				  }
				});
				
				inquireFinancePickupApplicationWarehouse2($this.parents("tr").attr("pickupId"));
			});
			
			//提交提货
			$("#wareHousePickupList .submitApplication").unbind("click").click(function(){
				var $this = $(this);
				var ii = layer.confirm('是否确认提交该条提货', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					submitFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"), function(){
						layer.close(ii);
						loadPickupList(oData);
					});
				});
			});
			
			$("#wareHousePickupList .cancel").unbind("click").click(function(){
				var $this = $(this);
				var ii = layer.confirm('是否确认取消该条提货', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					cancelFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"), function(){
						layer.close(ii);
					});
				});
			});
			
			//合同提交
			$("#wareHousePickupList .submit").unbind("click").click(function(){
				var $this = $(this);
				var ii = layer.confirm('是否确认提交合同', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					submitPickupContract($this.parents("tr").attr("pickupId"), function(){
						layer.close(ii);
					});
				});
			});
			
			//合同上传
			$("#wareHousePickupList .upload").unbind("click").click(function(){
				var $this = $(this);
				var ii = layer.open({
				  title: '上传合同',
				  type: 1,
				  skin: 'layui-layer-rim', //加上边框
				  area: ['1000px', '600px'], //宽高
				  content: html_financeContract,
				  btn: ['确定', '取消'],
				  yes: function(){
//				  	if ($this.parents("tr").attr("pickupState") == 8) {
//				  		layer.close(ii);
//				  		loadPickupList(oData);
//				  	} else {
				  		databind.submitDom($(".html_financeContract"), function(){
					  		layer.msg("提交成功！");
					  		layer.close(ii);
					  		loadPickupList(oData);
					  	});
//				  	}
				  }
				});
				$(".html_financeContract input[name=pickupId]").val($this.parents("tr").attr("pickupId"));
				if ($(this).parents("tr").attr("pickupState") == 3) {
					inquireFinanceFilesNormList();
				} else {
					$(".html_financeContract").attr("action", "updateWarehousePickupContract");
					inquireFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"));
				}
				
				$(".html_financeContract").on("click", ".deleteProductIntro", function() {
					var d = $(this).parent().parent().parent().parent().parent();
					$(this).parents("tr").remove();
					var fileUuid = [];
					var fileSign = [];
					for (var j = 0; j < d.find(".mas").length; j++) {
						fileUuid.push($(d.find(".mas")[j]).attr("fileUuid"));
						$(d.find(".mas")[j]).find(".fileIndex").html(j+1);
						if ($(d.find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
							fileSign.push(1);
						} else {
							fileSign.push(0);
						}
					}
					d.find("input[name=filesUuid]").val(fileUuid);
					d.find("input[name=filesSign]").val(fileSign);
				});
				
				$(".html_financeContract").on("click", "table input[type=checkbox]", function() {
					var d = $(this).parent().parent().parent().parent().parent();
					var fileSign = [];
					for (var j = 0; j < d.find("input[type=checkbox]").length; j++) {
						if ($(d.find("input[type=checkbox]")[j]).prop("checked")) {
							fileSign.push(1);
						} else {
							fileSign.push(0);
						}
					}
					d.find("input[name=filesSign]").val(fileSign);
				});
			});
			
			//解除监管
			$("#wareHousePickupList .release").unbind("click").click(function(){
				var $this = $(this);
				var ii = layer.confirm('是否确认解除监管', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					deregulationPickupApplicationWarehouse($this.parents("tr").attr("pickupId"), function(){
						layer.close(ii);
					});
				});
			});
		}, $("#wareHousePickupList .pagerCon"));
	}
	
	//查询所需附件列表
	var inquireFinanceFilesNormList = function() {
		base.fnAjax({
			action: "inquireFinanceFilesNormList.json",
			async: false, //同步异步
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $(".html_financeContract script").html();
					var html = juicer(tpl, data);
					$(".html_financeContract .normInfos").html(html);
					
					for (var i = 0; i < $(".html_financeContract .normFileName").length; i++) {
						var $this = $("#" + $($(".html_financeContract .normFileName")[i]).attr("id"));
						tools.fileupload($this, null, function (data, dom) {
							var d = $("#" + $(dom).attr("id"));
//							var str = '<tr fileUuid="'+data.result.data[0].fileUuid+'" class="mas"><td class="fileIndex"></td><td>'+data.result.data[0].fileName+'</td><td>'+d.parent().find("input[name=filesUuid]").attr("codeName")+'</td><td><input disabled="disabled" type="checkbox" value="1" /></td><td><a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.result.data[0].fileUuid + '" target="_blank">预览</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
							var str = '<tr fileUuid="'+data.result.data[0].fileUuid+'" class="mas"><td class="fileIndex"></td><td>'+data.result.data[0].fileName+'</td><td>'+d.parent().find("input[name=filesUuid]").attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.result.data[0].fileUuid + '" target="_blank">预览</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
							d.parent().find("table").append(str);
							var fileUuid = [];
							var fileSign = [];
							for (var j = 0; j < d.parent().find(".mas").length; j++) {
								fileUuid.push($(d.parent().find(".mas")[j]).attr("fileUuid"));
								$(d.parent().find(".mas")[j]).find(".fileIndex").html(j+1);
								if ($(d.parent().find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
									fileSign.push(1);
								} else {
									fileSign.push(0);
								}
							}
							d.parent().find("input[name=filesUuid]").val(fileUuid);
							d.parent().find("input[name=filesSign]").val(fileSign);
						});
					};
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	var inquireFinancePickupApplicationWarehouse1 = function(pickupId, isAll) {
		base.fnAjax({
			action : "inquireFinancePickupApplicationWarehouse.json",
			async : false, // 同步异步
			oData : {
				pickupId : pickupId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					databind.fillForm($(".html_documentSign"), data.datas[0]);
					
					$(".html_documentSign table").html("<tr><th><input type='checkbox' class='checkAll none'></th><th>No</th><th>文件名称</th><th>文件类型</th><th>状态</th><th>签署记录</th><th>退回原因</th><th>操作</th></tr>")
					var i = 1;
					$.each(data.datas[0].financeFilesInfoList, function() {
						var isSign = this.isSign;
						var filesInfoId = this.filesInfoId;
						var signState = this.fileSignState.split(',');
						var msg = [];
						if (this.msg != null) {
							msg = this.msg.split(',');
						}
						var j = 0;
						var fs1 = this.filesUuid.split(',');
						var ss1 = this.isSign.split(',');
//						$.each(this.filesUuid.split(','), function() {
						for (var x = 0; x < fs1.length; x++) {
							var _this = fs1[x];
							if ($.trim(_this) != "") {
								var m = msg[j];
								if (m == null || m == "null") {
									m = "";
								}
								var str;
								if (ss1[x] == '1') {
									str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input checked='checked' type='checkbox' class='checks none'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>签署文件</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='changeSign'>取消网签</a> <a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td><a href='javascript:void(0);' class='sign'>签章</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
								} else {
									str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input type='checkbox' class='none'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>附件</td><td>-</td><td></td><td></td><td><a href='javascript:void(0);' class='changeSign'>设为网签</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
								}
								if (str != null) {
									$(".html_documentSign table").append(str);
									i++;
									str = null;
								}
								m = "";
								j++;
							}
						};
						
						tools.addCheckAllEvent($(".html_documentSign .checks"), $(".html_documentSign .checkAll"));
					});
					
					//改变是否需要签署
					$(".html_documentSign .changeSign").unbind("click").click(function() {
						var $this = $(this);
						//询问框
						ii2 = layer.confirm('是否确认该操作？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							changeFileSign($this.parents("tr").attr("fileUuid"), pickupId, isAll);
						}, function(){
						  
						});
					});
					
					//查看签署记录
					$(".html_documentSign .showSignRecord").unbind("click").click(function() {
						var $this = $(this);
						
						layer.open({
						  type: 1,
						  title: "签章记录",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['820px', '500px'], //宽高
						  content: html_signFileSealList,
						  btn: ['确定']
						});
						
						tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": $this.parents("tr").attr("fileUuid"), "isAll": isAll}, function(){
							if (isAll == true) {
								$(".cancelPos").remove();
							}
						}, $(".signFileSealList .pagerCon"));
						
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					});
					
					$(".html_documentSign .sign").unbind("click").click(function(){
						var $this = $(this);
						if (isAll == true) {
							window.open("../app/index.htm?fileUuid="+$this.parents("tr").attr("fileUuid")+"&readOnly=readOnly&enterpriseId="+ei);
						} else {
							window.open("../app/index.htm?fileUuid="+$this.parents("tr").attr("fileUuid"));
						}
					});
					
					$(".html_documentSign .signAll").unbind("click").click(function(){
						var filesInfoIds = [];
						var fileUuids = [];
						record = true;
						
						$.each($(".html_documentSign .checks:checked"), function() {
							var $this = $(this);
							if ($this.parents("tr").attr("signState") == "6") {
								filesInfoIds.push($this.parents("tr").attr("filesInfoId"));
								fileUuids.push($this.parents("tr").attr("fileUuid"));
							}
							
							inquireSignFileSealInfoPageList($this.parents("tr").attr("fileUuid"));
							if (record == false) {
								$this.parents("table").find("tr").css("background-color", "#FFF");
								$this.parents("tr").css("background-color", "pink");
								return false;
							}
						});
						
						if (record == false) {
							base.alert(2, "还有合同尚未签章！");
							return;
						}
						
						if (0 == filesInfoIds.length || 0 == fileUuids.length) {
							base.alert(2, "请勾选需要签署的文件！");
							return;
						}
						
						ii3 = layer.open({
						content: '是否确认签署？',
							btn: ['确认', '取消'],
							shadeClose: false,
							yes: function(){
							  	createWarehousePickupPlatformDocumentSummarySignAll(pickupId, filesInfoIds, fileUuids, 2);
							}, no: function(){
								layer.close(ii3);
							}
						});
					});
					
					if (isAll == true) {
						$(".signAll").remove();
						$(".sign").html("签章查看");
					}
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	//取消文件签章位置
	var changeFileSign =function(fileUuid, pickupId, isAll){
		base.fnAjax({
			action : "changeFileSign.json",
			async : false, // 同步异步
			oData : {
				fileUuid: fileUuid
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
					layer.close(ii2);
					inquireFinancePickupApplicationWarehouse1(pickupId, isAll);
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//取消文件签章位置
	var changeFileSign1 =function(fileUuid, pickupId){
		base.fnAjax({
			action : "changeFileSign.json",
			async : false, // 同步异步
			oData : {
				fileUuid: fileUuid
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
					layer.close(ii2);
					inquireFinancePickupApplicationWarehouse3(pickupId);
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	var inquireFinancePickupApplicationWarehouse2 = function(pickupId) {
		base.fnAjax({
			action : "inquireFinancePickupApplicationWarehouse.json",
			async : false, // 同步异步
			oData : {
				pickupId : pickupId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					databind.fillForm($(".contractConfirm"), data.datas[0]);
					
					$(".contractConfirm table").html("<tr><th></th><th>文件名称</th><th>文件类型</th><th>状态</th><th>退回原因</th><th>合同修改</th><th>签署记录</th><th>返回信息</th><th style='text-align:center;'>操作</th></tr>")
					var i = 1;
					$.each(data.datas[0].financeFilesInfoList, function() {
						var isSign = this.isSign;
						var filesInfoId = this.filesInfoId;
						var signState = this.fileSignState.split(',');
						var msg = [];
						if (this.msg != null) {
							msg = this.msg.split(',');
						}
						var j = 0;
						var fs1 = this.filesUuid.split(',');
						var ss1 = this.isSign.split(',');
						var fileType = this.normFileName;
						for (var x = 0; x < fs1.length; x++) {
							var _this = fs1[x];
							if ($.trim(_this) != "") {
								var m = msg[j];
								if (m == null || m == "null") {
									m = "";
								}
								var str;
								if (ss1[x] == '1') {
									if (signState[j] != 6 && signState[j] != 5) {
										if (signState[j] == 1) {
											str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a href='javascript:void(0);' class='confirm'>确认</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a> <a href='javascript:void(0);' class='callBack'>打回</a></td></tr>";
										} else {
											str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a> <a href='javascript:void(0);' class='callBack'>打回</a></td></tr>";
										}
									} else {
										str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
									}
								} else {
									if (signState[j] != 6 && signState[j] != 5) {
										str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(80, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td></td><td></td><td style='text-align:right;'><a href='javascript:void(0);' class='confirm'>确认</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a> <a href='javascript:void(0);' class='callBack'>打回</a></td></tr>";
									} else {
										str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(80, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td></td><td></td><td style='text-align:right;'><a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
									}
								}
								if (str != null) {
									$(".contractConfirm table").append(str);
									i++;
									str = null;
								}
								m = "";
								j++;
							}
						};
						
					});
					
					//合同打回
					$(".contractConfirm .callBack").unbind("click").click(function(){
						var ii = layer.open({
						  type: 1,
						  title: "退回理由",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".signCallback"), function(){
						  		layer.msg("退回成功！");
						  		layer.close(ii);
						  		inquireFinancePickupApplicationWarehouse2(pickupId);
						  	});
						  }
						});
						
						$(".signCallback input[name=fileUuid]").val($(this).parents("tr").attr("fileUuid"));
						$(".signCallback input[name=pickupId]").val(pickupId);
					});
					
					//合同批量打回
					$(".contractConfirm .callbackAll").unbind("click").click(function(){
						var ii = layer.open({
						  type: 1,
						  title: "退回理由",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallbackAll,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".signCallbackAll"), function(){
						  		layer.msg("退回成功！");
						  		layer.close(ii);
						  		inquireFinancePickupApplicationWarehouse2(pickupId);
						  	});
						  }
						});
						
						$(".signCallbackAll input[name=pickupId]").val(pickupId);
					});
					
					//合同确认
					$(".contractConfirm .confirm").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						//询问框
						ii4 = layer.confirm('是否确认该合同', {
						  btn: ['确定','取消'] //按钮
						}, function(){
						  confirmWarehousePickupContract(pickupId, fuid);
						}, function(){
						  
						});
						
						$("input[name=fileUuid]").val(fuid);
					});
					
					//批量合同确认
					$(".contractConfirm .confrimAll").unbind("click").click(function(){
						//询问框
						ii4 = layer.confirm('是否确认合同', {
						  btn: ['确定','取消'] //按钮
						}, function(){
						  confirmWarehousePickupContractAll(pickupId);
						}, function(){
						  
						});
					});
					
					//退回原因
					$(".contractConfirm .callBackDetail").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						
						var ii = layer.open({
						  type: 1,
						  title: "退回理由",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定']
						});
						
						$("textarea[name=remark]").attr({"name": "callbackReamrk", "readOnly": "readOnly"}).css("border", "none");
						
						databind.fillInput($(".signCallback"), {
							action: "inquireFinanceFilesInfoDetail.json?fileUuid="+fuid,
							version: "v1.0"
						});
					});
					
					//修改原因
					$(".contractConfirm .updateDetail").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						
						var ii = layer.open({
						  type: 1,
						  title: "合同修改",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定']
						});
						
						$("textarea[name=remark]").attr({"name": "updateReamark", "readOnly": "readOnly"}).css("border", "none");
						
						databind.fillInput($(".signCallback"), {
							action: "inquireFinanceFilesInfoDetail.json?fileUuid="+fuid,
							version: "v1.0"
						});
					});
					
					//查看签署记录
					$(".contractConfirm .showSignRecord").unbind("click").click(function() {
						var $this = $(this);
						
						layer.open({
						  type: 1,
						  title: "签章记录",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['820px', '500px'], //宽高
						  content: html_signFileSealList,
						  btn: ['确定']
						});
						
						tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": $this.parents("tr").attr("fileUuid")}, function(){
							
						}, $(".signFileSealList .pagerCon"));
						
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	//查询代采代销提货详情
	var inquireFinancePickupApplicationWarehouse = function(pickupId) {
		base.fnAjax({
			action: "inquireFinancePickupApplicationWarehouse.json",
			async: false, //同步异步
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					databind.fillForm($(".html_financeContract"), data.datas[0]);
					var tpl = '{@each datas as it, index}' +
							'{@each it.financeFilesInfoList as item, index}' +
							'<div style="margin-top: 15px;">' +
							'<input type="hidden" name="filesInfoId" value="${item.filesInfoId}" />' +
							'<input isNull="${item.isNotNull}" codeName="${item.normFileName}" type="hidden" value="${item.filesUuid}" name="filesUuid" />' +
							'<input type="hidden" name="filesSign" value="${item.isSign}" />' +
							'<input type="hidden" name="fileSignState" value="${item.fileSignState}" />' +
							'<input multiple="multiple" type="file" id="normFileName${index}" name="file" class="none normFileName" />' +
							'<span class="none${item.isNotNull}" style="color: red;">*</span><span>${item.normFileName}：</span><label for="normFileName${index}" class="productIntro">添加</label>' +
							'<table style="border: none;">' +
							'	<tr>' +
							'		<th width="5%" style="padding-left: 0;">No</th>' +
							'		<th width="55%" >文件名称</th>' +
							'		<th width="10%" >附件类型</th>' +
							'		<th width="10%" >签署</th>' +
							'		<th width="20%" >操作</th>' +
							'	</tr>' +
							'</table>' +
							'</div>' +
							'{@/each}' +
							'{@/each}';
					var html = juicer(tpl, data);
					$(".html_financeContract .normInfos").html(html);
					
					$.each($(".html_financeContract input[name=filesUuid]"), function(){
						var $this1 = $(this);
						var fs1 = $this1.val().split(',');
						var ss1 = $this1.parent().find("input[name=filesSign]").val().split(',');
						var signState = $this1.parent().find("input[name=fileSignState]").val().split(',');
						for(var x = 0; x < fs1.length; x++){
							var f = fs1[x];
							if (f != "") {
								if (ss1[x] == "1") {
									if (signState[x] == 5 || signState[x] == 4) {
										var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input checked="checked" type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="replace">替换</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
//										var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="deleteProductIntro">删除</a> <a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.datas[0].fileUuid + '" target="_blank">预览</a></td></tr>';
										$this1.parent().find("table").append(str);
									} else {
										var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input checked="checked" type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
										$this1.parent().find("table").append(str);
									}
								} else {
									if (signState[x] == 5 || signState[x] == 4) {
										var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="replace">替换</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
//										var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="deleteProductIntro">删除</a> <a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.datas[0].fileUuid + '" target="_blank">预览</a></td></tr>';
										$this1.parent().find("table").append(str);
									} else {
										var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
										$this1.parent().find("table").append(str);
									}
								}
							}
						};
					});
//					$(".html_financeContract input[type=checkbox]").attr("disabled", "disabled");
					
					
					$(".html_financeContract .replace").unbind("click").click(function(){
						var ii = layer.open({
						  type: 1,
						  title: "合同修改",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signReplace,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".signReplace"), function(){
						  		layer.msg("修改成功！");
						  		layer.close(ii);
						  		tf = true;
						  		inquireFinancePickupApplicationWarehouse(pickupId);
						  	});
						  }
						});
						
						$(".signReplace input[name=pickupId]").val(pickupId);
						$(".signReplace input[name=oldFileUuid]").val($(this).parents("tr").attr("fileUuid"));
						tools.fileupload($("#newFile"), null, function (data, dom) {
							var str = '<a target="_blank" href="/finance/api/v1.0/downloadFile.file?fileUuid='+data.result.data[0].fileUuid+'">'+data.result.data[0].fileName+'</a>';
							$("#newFile").parent().find("span").html(str);
							$(".signReplace input[name=newFileUuid]").val(data.result.data[0].fileUuid);
						});
					});
					
					for (var i = 0; i < $(".html_financeContract .normFileName").length; i++) {
						var $this = $("#" + $($(".html_financeContract .normFileName")[i]).attr("id"));
						tools.fileupload($this, null, function (data, dom) {
							var d = $("#" + $(dom).attr("id"));
//							var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.result.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.result.data[0].fileUuid + '" class="showProductIntro">' + data.result.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
							var str = '<tr fileUuid="'+data.result.data[0].fileUuid+'" class="mas"><td class="fileIndex"></td><td>'+data.result.data[0].fileName+'</td><td>'+d.parent().find("input[name=filesUuid]").attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.result.data[0].fileUuid + '" target="_blank">预览</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
//							d.parent().find(".productIntro").before(str);
							d.parent().find("table").append(str);
							var fileUuid = [];
							var fileSign = [];
							for (var j = 0; j < d.parent().find(".mas").length; j++) {
								fileUuid.push($(d.parent().find(".mas")[j]).attr("fileUuid"));
								$(d.parent().find(".mas")[j]).find(".fileIndex").html(j+1);
								if ($(d.parent().find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
									fileSign.push(1);
								} else {
									fileSign.push(0);
								}
							}
							d.parent().find("input[name=filesUuid]").val(fileUuid);
							d.parent().find("input[name=filesSign]").val(fileSign);
						});
					};
					
					if (data.datas[0].pickupState == 8 || tf == true) {
//						$(".html_financeContract .deleteProductIntro").remove();
					}
					
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//提交提货
	var submitFinancePickupApplicationWarehouse = function(pickupId, callback) {
		base.fnAjax({
			action: "submitFinancePickupApplicationWarehouse.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "提交成功！");
				}else {
					base.alert(3, data.message);
				}
				callback();
			}
		});
	};
	
	//解除监管
	var deregulationPickupApplicationWarehouse = function(pickupId, callback) {
		base.fnAjax({
			action: "deregulationPickupApplicationWarehouse.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "解除监管成功！");
					router.route("warehousePickup/wareHousePickupList.html");
				}else {
					base.alert(3, data.message);
				}
				callback();
			}
		});
	};
	
	//取消提货
	var cancelFinancePickupApplicationWarehouse = function(pickupId, callback) {
		base.fnAjax({
			action: "cancelFinancePickupApplicationWarehouse.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "取消成功！");
					router.route("warehousePickup/wareHousePickupList.html");
				}else {
					base.alert(3, data.message);
				}
				callback();
			}
		});
	};
	
	//合同确认
	var confirmWarehousePickupContract = function(pickupId, fileUuid) {
		base.fnAjax({
			action: "confirmWarehousePickupContract.json",
			async: false,
			oData: {
				pickupId: pickupId,
				fileUuid: fileUuid
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "确认成功！");
					inquireFinancePickupApplicationWarehouse2(pickupId);
				}else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//合同批量确认
	var confirmWarehousePickupContractAll = function(pickupId) {
		base.fnAjax({
			action: "confirmWarehousePickupContractAll.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "确认成功！");
					inquireFinancePickupApplicationWarehouse2(pickupId);
				}else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//合同提交
	var submitPickupContract = function(pickupId) {
		base.fnAjax({
			action: "submitPickupContract.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "提交成功！");
					router.route("warehousePickup/wareHousePickupList.html");
				}else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//取消文件签章位置
	var cancelSealPos =function(signFileSealId, fileUuid){
		base.fnAjax({
			action : "cancelSealPos.json",
			async : false, // 同步异步
			oData : {
				signFileSealId: signFileSealId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
					layer.close(ii2);
					tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": fileUuid}, function(){
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					}, $(".signFileSealList .pagerCon"));
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//查询文件印章信息
	var inquireSignFileSealInfoPageList =function(fileUuid){
		base.fnAjax({
			action : "inquireSignFileSealInfoPageList.json",
			async : false, // 同步异步
			oData : {
				fileUuid: fileUuid,
				signState: 0
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					if (data.datas.length == 0) {
						record = false;
					}
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//批量签署
	var createWarehousePickupPlatformDocumentSummarySignAll = function(pickupId, filesInfoId, fileUuid, sealType){
		base.fnAjax({
			action : "createWarehousePickupPlatformDocumentSummarySignAll.json",
			async : false, // 同步异步
			oData : {
				filesInfoId: filesInfoId,
				fileUuid: fileUuid,
				sealType: sealType,
				pickupId: pickupId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					layer.close(ii3);
					layer.close(ii);
					base.alert(1, "签署成功！");
					router.route("warehousePickup/wareHousePickupList.html");
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
		//查询融资详情
	var inquireFinanceApplicationDetail = function(dom,financeId) {
		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",
			nocode: true,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var d = {};
					d.loanDate = data.datas[0].loanDate;
					d.loanAmount = tools.formatCurrency(data.datas[0].loanAmount);
					d.intrerst = data.datas[0].auditInterest;
					d.pledgeRate = (parseFloat(data.datas[0].financeAuditDetail.financeAmount)*100/parseFloat(data.datas[0].bulkstocks[0].finalPrice)).toFixed(2);
					d.financeDays = data.datas[0].financeProductInnerDetail.financeDays;
					d.bulkstockPrice = tools.formatCurrency(data.datas[0].bulkstocks[0].bulkstockPrice);
					d.financePrice = tools.formatCurrency(data.datas[0].bulkstocks[0].financePrice);
					
					databind.fillForm(dom, d);
					
					dom.attr("isNull", "1");
				}else {
					//
				}
			}
		})
	};
	
	var inquireFinancePickupApplicationWarehouse3 = function(pickupId) {
		base.fnAjax({
			action : "inquireFinancePickupApplicationWarehouse.json",
			async : false, // 同步异步
			oData : {
				pickupId : pickupId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					databind.fillForm($("#warehousePickupdocumentSign"), data.datas[0]);
					
					$("#warehousePickupdocumentSign table").html("<tr><th><input type='checkbox' class='checkAll'></th><th></th><th>文件名称</th><th>文件类型</th><th>状态</th><th>退回原因</th><th>合同修改</th><th>签署记录</th><th>返回信息</th><th style='text-align:center;'>操作</th></tr>")
					ei=data.datas[0].enterpriseId;
					var i = 1;
					$.each(data.datas[0].financeFilesInfoList, function() {
						var isSign = this.isSign;
						var filesInfoId = this.filesInfoId;
						var signState = this.fileSignState.split(',');
						var msg = [];
						if (this.msg != null) {
							msg = this.msg.split(',');
						}
						var j = 0;
						var fs1 = this.filesUuid.split(',');
						var ss1 = this.isSign.split(',');
						var fileType = this.normFileName;
//						$.each(this.filesUuid.split(','), function() {
						for (var x = 0; x < fs1.length; x++) {
							var _this = fs1[x];
							if ($.trim(_this) != "") {
								var m = msg[j];
								if (m == null || m == "null") {
									m = "";
								}
								var str;
								if (ss1[x] == '1') {
									if (signState[j] != 0) {
										str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input checked='checked' disabled='disabled' type='checkbox' class='checks'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a href='javascript:void(0);' class='changeSign'>取消网签</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
									} else {
										str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input checked='checked' type='checkbox' class='checks'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a href='javascript:void(0);' class='changeSign'>取消网签</a>  <a href='javascript:void(0);' class='sign'>查看</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
									}
								} else {
									str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input type='checkbox' disabled='disabled'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>-</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td></td><td></td><td style='text-align:right;'><a href='javascript:void(0);' class='changeSign'>设为网签</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
								}
								if (str != null) {
									$("#warehousePickupdocumentSign table").append(str);
									i++;
									str = null;
								}
								m = "";
								j++;
							}
						};
						
						tools.addCheckAllEvent($("#warehousePickupdocumentSign .checks"), $("#warehousePickupdocumentSign .checkAll"));
					});
					
					//改变是否需要签署
					$(".changeSign").unbind("click").click(function() {
						var $this = $(this);
						//询问框
						ii2 = layer.confirm('是否确认该操作？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							changeFileSign1($this.parents("tr").attr("fileUuid"), pickupId);
						}, function(){
						  
						});
					});
					
					//退回原因
					$(".callBackDetail").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						
						var ii = layer.open({
						  type: 1,
						  title: "退回理由",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定']
						});
						
						$("textarea[name=remark]").attr({"name": "callbackReamrk", "readOnly": "readOnly"}).css("border", "none");
						
						databind.fillInput($(".signCallback"), {
							action: "inquireFinanceFilesInfoDetail.json?fileUuid="+fuid,
							version: "v1.0"
						});
					});
					
					//修改原因
					$(".updateDetail").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						
						var ii = layer.open({
						  type: 1,
						  title: "合同修改",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定']
						});
						
						$("textarea[name=remark]").attr({"name": "updateReamark", "readOnly": "readOnly"}).css("border", "none");
						
						databind.fillInput($(".signCallback"), {
							action: "inquireFinanceFilesInfoDetail.json?fileUuid="+fuid,
							version: "v1.0"
						});
					});
					
					$("#warehousePickupdocumentSign").on("click", ".sign", function(){
						var $this = $(this);
						window.open("../app/index.htm?fileUuid="+$this.parents("tr").attr("fileUuid")+"&readOnly=readOnly&enterpriseId="+ei);
					});
					
					//查看签署记录
					$("#warehousePickupdocumentSign").on("click", ".showSignRecord", function(){
						var $this = $(this);
						
						layer.open({
						  type: 1,
						  title: "签章记录",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['820px', '500px'], //宽高
						  content: html_signFileSealList,
						  btn: ['确定']
						});
						
						tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": $this.parents("tr").attr("fileUuid"), "isAll": "true"}, function(){
							$(".cancelPos").remove();
						}, $(".signFileSealList .pagerCon"));
						
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					});
								
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	return {
		init: init
	};
});